package com.person.yhzs.family.mapper;

import com.person.yhzs.family.entity.Family;
import com.person.yhzs.family.entity.UserFamily;
import com.person.yhzs.family.entity.dto.FamilyDto;
import com.person.yhzs.family.entity.vo.FamilyPersonTreeModelVo;
import com.person.yhzs.family.entity.vo.FamilyVo;
import com.person.yhzs.user.entity.vo.UserVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author luolin
 * @version 1.0.0
 * @ClassName FamilyMapper.java
 * @Description TODO
 * @createTime 2022年05月30日 10:18:00
 */
@Mapper
public interface FamilyMapper {

    /**
     * @Description //增加家谱
     * @Author luolin
     * @Date 2022/5/30 10:25
     * @param family
     **/
    Integer insertFamilyTemplate(@Param("family") Family family);

    /**
     * 检查家谱是否存在
     * @param familyName
     * @return
     */
    Long checkFamilyIsHave(@Param("familyName") String familyName);

    /**
     * @Description //增加家谱
     * @Author luolin
     * @Date 2022/5/30 10:25
     * @param family
     **/
    Integer addFamily(@Param("family") Family family);

    /**
     * @Description //查询单个家谱
     * @Author luolin
     * @Date 2022/5/30 10:28
     **/
    FamilyVo queryFamilyOne(@Param("familyDto") FamilyDto familyDto);

    /**
     * @Description //查询家谱列表
     * @Author luolin
     * @Date 2022/5/30 10:31
     **/
    List<FamilyVo> queryFamilyList(@Param("familyDto") FamilyDto familyDto, @Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize);

    /**
     * @Description //查询家谱总数
     * @Author luolin
     * @Date 2022/5/30 16:30
     **/
    Long listFamilyCount(@Param("familyDto") FamilyDto familyDto);

    /**
     * 加入家谱
     * @param userFamily
     * @return
     */
    Long joinFamily(@Param("userFamily")UserFamily userFamily);

    /**
     * @Description 修改家族成员,父子节点关系
     * @Author luolin
     * @Date 2022/10/8 11:48
     **/
    Long updateFamilyUserPId(@Param("familyId") Long familyId,@Param("userId") Long userId,@Param("pId") Long pId);

    /**
     * @Description 修改家族成员,父子节点关系,通过关系ID
     * @Author luolin
     * @Date 2022/10/8 11:48
     **/
    Long updateFamilyUserRelationPId(@Param("relationId") Long relationId,@Param("relationPId") Long relationPId);

    /**
     * 修改家族信息
     * @Author luolin
     * @Date 2022/5/31 13:12
     **/
    Long editFamily(@Param("family") Family family);

    /**
     * 修改家谱人员的配偶
     * @Description
     * @Author luolin
     * @Date 2022/10/8 9:57 
     **/
    Long updateFamilyPersonMate(@Param("familyId") Long familyId,@Param("userId") Long userId,@Param("mateId") Long mateId);

    /**
     * 修改家谱人员的配偶
     * @Description
     * @Author luolin
     * @Date 2022/10/8 9:57
     **/
    Long deleteFamilyPersonMateByRelationId(@Param("relationId") Long relationId);

    /**
     * 修改家谱人员的配偶，通过关系ID修改
     * @Description
     * @Author luolin
     * @Date 2022/10/8 9:57
     **/
    Long updateFamilyPersonMateByRelationId(@Param("relationId") Long relationId,@Param("mateId") Long mateId);

    /**
     * 通过家谱和人员查询家谱中人员的关系信息
     */
    FamilyPersonTreeModelVo selectUserFamilyByUser(@Param("familyId") Long familyId,@Param("userId") Long userId);

    /**
     * 通过关系ID查询家谱中人员的关系信息
     */
    FamilyPersonTreeModelVo selectUserFamilyByRelationId(@Param("relationId") Long relationId);

    /**
     * 新增家谱的人员信息
     * @param userId
     * @param familyId
     * @param pId
     * @return
     */
    Long insertFamilyPerson(@Param("familyId") Long familyId,@Param("userId") Long userId,@Param("relationPId") Long relationPId);


    /**
     * 校验是否加入了家族
     * @Author luolin
     * @Date 2022/5/31 13:25
     **/
    Long checkJoinFamily(@Param("userId") Long userId,@Param("familyId") Long familyId);

    /**
     *  查询某个家族的成员
     * @param familyId
     * @return
     */
    List<UserVo> queryUserByFamilyId(@Param("familyId") Long familyId);

    /**
     * 查询某个家谱的所有成员
     * @Author luolin
     * @Date 2022/9/23 14:04
     **/
    List<FamilyPersonTreeModelVo> getFamilyPersonList(@Param("familyId") Long familyId);

    /**
     * 查询某个家谱的某个成员
     * @Author luolin
     * @Date 2022/9/23 14:04
     **/
    FamilyPersonTreeModelVo getFamilyPersonOne(@Param("familyId") Long familyId,@Param("userId") Long userId);

    /**
     * 查询某个家谱的某个成员，通过关系id
     * @Author luolin
     * @Date 2022/9/23 14:04
     **/
    FamilyPersonTreeModelVo getFamilyPersonOneByRelationId(@Param("relationId") Long relationId);

    /**
     * @Description 查询用户的家庭信息
     * @Author luolin
     * @Date 2022/9/29 14:46
     **/
    FamilyPersonTreeModelVo selectUserFamilyInfo(@Param("familyId") Long familyId,@Param("userId") Long userId);

    /**
     * @Description 查询用户的家庭信息，通过关系ID
     * @Author luolin
     * @Date 2022/9/29 14:46
     **/
    FamilyPersonTreeModelVo selectUserFamilyInfoByRelationId(@Param("relationId") Long relationId);

    /**
     * @Description 修改用户的家谱关系
     * @Author luolin
     * @Date 2022/9/30 17:25
     **/
    Long updateUserFamily(@Param("userFamily") FamilyPersonTreeModelVo userFamily,@Param("familyId")Long familyId,@Param("userId") Long userId);

    /**
     * @Description 移除家谱人员（个人）
     * @Author luolin
     * @Date 2022/10/14 10:03 
     **/
    Long removeFamilyPersonSelf(@Param("familyId") Long familyId, @Param("userId") Long userId);

    /**
     * @Description 通过关系id，移除家谱人员（个人）
     * @Author luolin
     * @Date 2022/10/14 10:03
     **/
    Long removeFamilyPersonSelfByRelationId(@Param("relationId") Long relationId);

    /**
     * @Description 检查家谱人员数量
     * @Author luolin
     * @Date 2022/10/24 17:15
     **/
    Long checkFamilyNumber(@Param("familyId") Long familyId);

    /**
     * @Description 删除家谱信息
     * @Author luolin
     * @Date 2022/10/24 17:15
     **/
    Long deleteFamily(@Param("familyId") Long familyId);

    /**
     * @Description 删除所有家谱人员
     * @Author luolin
     * @Date 2022/10/24 17:15
     **/
    Long deleteFamilyPersonAll(@Param("familyId") Long familyId);

    /**
     * @Description 删除家谱人员（个人）
     * @Author luolin
     * @Date 2022/10/14 10:03
     **/
    Long deleteFamilyPersonSelf(@Param("familyId") Long familyId, @Param("userId") Long userId);

    Long deleteFamilyPersonSelfRelation(@Param("relationId") Long relationId);

    /**
     * @Description 删除家谱人员（多人）
     * @Author luolin
     * @Date 2022/10/14 10:03
     **/
    Long deleteFamilyPersonBatch(@Param("familyId") Long familyId, @Param("relationIds") Set<Long> relationIds);

    /**
     * @Description 检查家谱人员是否有子人员
     * @Author luolin
     * @Date 2022/10/14 10:03
     **/
    Long checkFamilyPersonChild(@Param("familyId") Long familyId, @Param("userId") Long userId);

    /**
     * @Description 检查关系中是否还有子关系
     * @Author luolin
     * @Date 2022/10/14 10:03
     **/
    Long checkFamilyPersonChildRelation(@Param("relationId") Long relationId);

    /**
     * @Description 修改关系表的userId
     * @Author luolin
     * @Date 2022/10/14 14:44
     **/
    Long updateFamilyRelationUserId(@Param("relationId") Long relationId, @Param("replaceId") Long replaceId);

    /**
     * @Description 修改关系表的mateId
     * @Author luolin
     * @Date 2022/10/14 14:44
     **/
    Long updateFamilyRelationMateId(@Param("relationId") Long relationId, @Param("replaceId") Long replaceId);



    /**
     * @Description 批量修改Pid
     * @Author luolin
     * @Date 2022/10/14 14:44
     **/
    Long batchUpdateFamilyRelationPid(@Param("familyId") Long familyId, @Param("userId") Long userId, @Param("replaceId") Long replaceId);

    /**
     * @Description pId批量查找某个人下的人员
     * @Author luolin
     * @Date 2022/10/19 13:50
     **/
    List<Long> selectBatchUserByPid(@Param("familyId") Long familyId, @Param("pId") Long pId);

}
